﻿using Pdf2epub.ExtractStrategy;
using Pdf2epub.Model;
using System.Collections.Generic;
using System.Linq;

namespace Pdf2epub.Helpers
{
    internal static class TableHelper
    {
        public static int GetColumnCount(ContentBlock tableBlock)
        {
            IEnumerable<ContentBlock> rows = tableBlock.SubBlocks.Where(block => (block.ContentType == ContentType.TableRow) || (block.ContentType == ContentType.TableCaption)).ToArray();
            if (!rows.Any())
                return 0;

            return rows.Max(block => block.SubBlocks.Count);
        }

        public static int GetRowCount(ContentBlock tableBlock)
        {
            return tableBlock.SubBlocks.Count(block => (block.ContentType == ContentType.TableRow) || (block.ContentType == ContentType.TableCaption));
        }
    }
}